package com.fengye.school.model.convertors;

import com.fengye.school.model.school.enums.SubjectLanguageType;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

/**
 * 泛型指的是你在实体用的类型，第二个是指需要映射到数据库的类型对应的java中的类型
 */
@Converter(autoApply = true)
public class SubjectLanguageTypeConverter implements AttributeConverter<SubjectLanguageType, String> {


    @Override
    public String convertToDatabaseColumn(SubjectLanguageType attribute) {
        return attribute.getName();
    }

    @Override
    public SubjectLanguageType convertToEntityAttribute(String dbData) {
        return SubjectLanguageType.valueOf(dbData);
    }
}